<template>
	<view class="house-pages">
		<SelectHouse :info="selectInfo" page='houseInfo'></SelectHouse>
		<view class="info-block">
			<view class="title-info">
				<view class="title-item">
					<view class="line"></view>
					<view class="title">房屋信息</view>
				</view>
				<view class="title-item">
					<view class="name">{{info.houseType}}</view>
				</view>
			</view>
			<view class="tab-block">
				<view class="address-blick">
					<view class="address-title">地址</view>
					<view class="address-info">
						<view class="address-item">
							<view class="address-text">{{ info.areaName || '-' }}{{ info.streetName || '-' }}</view>
							<view class="address-text grey">街（巷、路）</view>
						</view>
						<view class="address-item">
							<view class="address-text">{{ info.buildingNumber || '-' }}</view>
							<view class="address-text grey">号（楼、院）</view>
						</view>
						<view class="address-item">
							<view class="address-text">{{ info.unitNumber || '-' }}</view>
							<view class="address-text grey">单元</view>
							<view class="address-text">{{ info.floorLevel || '-' }}</view>
							<view class="address-text grey">楼</view>
							<view class="address-text">{{ info.roomNumber || '-' }}</view>
							<view class="address-text grey">号</view>
						</view>
					</view>
				</view>
				<view class="tab-item">
					<view class="tab-info">
						<view class="tab-title">租赁证编号</view>
						<view class="tab-name">{{info.leaseCertificateNumber || '-'}}</view>
					</view>
					<view class="tab-info">
						<view class="tab-title">方位</view>
						<view class="tab-name">{{info.houseDirection || '-'}}</view>
					</view>
					<view class="tab-info">
						<view class="tab-title">结构</view>
						<view class="tab-name">{{info.structureType || '-'}}</view>
					</view>
					<view class="tab-info">
						<view class="tab-title">地段</view>
						<view class="tab-name">{{info.houseAreaType? info.houseAreaType + '段' : '-'}}</view>
					</view>
					<view class="tab-info">
						<view class="tab-title">建筑面积</view>
						<view class="tab-name">{{info.buildingArea? info.buildingArea + '㎡' : '-'}}</view>
					</view>
					<view class="tab-info">
						<view class="tab-title">使用面积</view>
						<view class="tab-name">{{info.usableArea ? info.usableArea + '㎡' : '-'}}</view>
					</view>
				</view>
			</view>
		</view>
		<view class="info-block" style="margin-bottom: 50rpx;">
			<view class="title-info">
				<view class="title-item">
					<view class="line"></view>
					<view class="title">租赁信息</view>
				</view>
				<view class="title-item">
					<image :src="imgStorage+'/login/lianzu.png'" class="info-icon" v-if="info.type==1"></image>
					<image :src="imgStorage+'/login/gongzu.png'" class="info-icon" v-else-if="info.type==2"></image>
					<image :src="imgStorage+'/login/zhiguan.png'" class="info-icon" v-else-if="info.type==3"></image>
					<view class="name">{{info.houseType}}</view>
				</view>
			</view>
			<view class="form-item">
				<view class="form-name">应交标准</view>
				<view class="form-info">
					<view class="form-content">
						{{info.unitPricePerSquare?info.unitPricePerSquare+'元/㎡' : '-'}}{{areaType?areaType:''}}
					</view>
				</view>
			</view>
			<view class="form-item">
				<view class="form-name">实收标准</view>
				<view class="form-info">
					<view class="form-content">
						{{info.calculatedPrice?info.calculatedPrice+'元/㎡' : '-'}}{{areaType?areaType:''}}
					</view>
					<view class="iconfont icon-a-jinggao1" @click="navigate('/page_pack/rent_payment/rent_calculator')">
					</view>
				</view>
			</view>
			<view class="form-item">
				<view class="form-name">应交月租金</view>
				<view class="form-info">
					<view class="form-content">{{info.totalPrice || '-'}}元</view>
					<view class="iconfont icon-a-jinggao1" @click="navigate('/page_pack/rent_payment/rent_calculator')">
					</view>
				</view>
			</view>
			<view class="form-item">
				<view class="form-name">房租到期时间</view>
				<view class="form-info">
					<view class="form-content">{{info.fwPaymentEnd || '-'}}</view>
				</view>
			</view>
			<view class="form-item">
				<view class="form-name">备注</view>
				<view class="form-info">
					<view class="form-content grey">{{info.remarks || '-'}}</view>
				</view>
			</view>
		</view>
		<view class="invoice" @click="navigate('/page_pack/authentication/authentication')">有多套住房？点击添加</view>
	</view>
</template>

<script>
	import {
		SelectHouse
	} from '@/components/SelectHouse.vue'
	import {
		getStorage
	} from '@/util/auth.js';
	import {
		getHousingInformation
	} from '@/api/authentication.js'
	export default {
		components: {
			SelectHouse
		},
		data() {
			return {
				// 带默认值的响应式数据对象
				info: {
					// 房屋信息
					houseType: '', // 房屋类型
					areaName: '', // 区域名称
					streetName: '', // 街道名称
					buildingNumber: '', // 建筑物编号
					unitNumber: '', // 单元号
					floorLevel: '', // 楼层
					roomNumber: '', // 房间号
					leaseCertificateNumber: '', // 租赁证编号
					houseDirection: '', // 方位
					structureType: '', // 结构类型
					houseAreaType: '', // 地段类型
					buildingArea: '', // 建筑面积
					usableArea: '', // 使用面积
					// 租赁信息
					housingType: 0, // 住房类型（1-廉租 2-公租 3-直管）
					unitPricePerSquare: '', // 应交标准
					calculatedPrice: '', // 实收标准
					totalPrice: '', // 月租金
					fwPaymentEnd: '', // 到期时间
					remarks: '' // 备注
				},
				selectInfo: {}
			}
		},
		computed: {
			areaType() {
				return this.info.houseType.includes("公租") ? '(建筑面积)' : '(使用面积)';
			}
		},
		methods: {
			obtainHousingInformation() {
				getHousingInformation().then(res => {
					const safeRes = Array.isArray(res) ? res : [];
					const targetId = this.selectInfo?.id;

					if (targetId) {
						const matchedData = safeRes.find(item => item.id === targetId);
						this.info = matchedData || {};
					} else {
						console.error("selectInfo或ID缺失");
					}
				})
			}
		},
		onLoad() {
			this.obtainHousingInformation()
		},
		onShow() {
			this.selectInfo = getStorage('selectInfo')
			this.obtainHousingInformation()
		}
	}
</script>

<style lang="scss" scoped>
	.house-pages {
		padding: 30rpx;

		.title-info {
			display: flex;
			align-items: center;
			justify-content: space-between;
			margin-bottom: 40rpx;

			.title-item {
				display: flex;
				align-items: center;

				.line {
					width: 18rpx;
					height: 36rpx;
					background-color: $theme-color;
					border-radius: 40rpx;
					margin-right: 14rpx;
				}

				.title {
					font-size: 32rpx;
					font-weight: bold;
				}

				.info-icon {
					width: 30rpx;
					height: 30rpx;
					margin-right: 10rpx;
				}

				.name {
					font-size: 28rpx;
				}
			}
		}

		.grey {
			color: #767676;
		}

		.info-block {
			padding: 30rpx;
			background-color: #fff;
			margin-top: 20rpx;
			border-radius: 30rpx;

			.form-item:last-child {
				margin-bottom: 0;
				padding-bottom: 0;
				border-bottom: none;
			}

			.form-item {
				display: flex;
				align-items: center;
				justify-content: space-between;
				margin-bottom: 30rpx;
				border-bottom: 1px solid #f7f7f7;
				padding-bottom: 40rpx;

				.form-name {
					font-size: 30rpx;
				}

				.form-info {
					display: flex;
					align-items: center;

					.form-content {
						font-size: 30rpx;
					}

					.iconfont {
						font-size: 32rpx;
						color: #767676;
						margin-left: 10rpx;
					}
				}
			}

			.tab-block {
				border: 1px solid #eeeeee;

				.address-blick {
					display: flex;

					.address-title {
						width: 30%;
						display: flex;
						align-items: center;
						justify-content: center;
						border-right: 1px solid #eeeeee;
						font-weight: bold;
						font-size: 28rpx;
					}

					.address-info {
						width: 70%;

						.address-item:last-child {
							border-bottom: none;
						}

						.address-item {
							border-bottom: 1px solid #eeeeee;
							display: flex;
							align-items: center;
							justify-content: center;
							font-size: 28rpx;
							line-height: 80rpx;

							.address-text {
								margin-right: 6rpx;
								overflow: hidden;
								text-overflow: ellipsis;
								white-space: nowrap;
							}
						}
					}
				}

				.tab-item {
					display: flex;
					flex-wrap: wrap;

					.tab-info:nth-child(2n) {
						.tab-name {
							border-right: none;
						}
					}

					.tab-info {
						width: 50%;
						border-top: 1px solid #eeeeee;
						display: flex;
						align-items: center;
						justify-content: center;
						font-size: 28rpx;
						line-height: 80rpx;

						.tab-title {
							width: 50%;
							display: flex;
							align-items: center;
							justify-content: center;
							border-right: 1px solid #eeeeee;
							font-weight: bold;
						}

						.tab-name {
							width: 50%;
							display: flex;
							align-items: center;
							justify-content: center;
							border-right: 1px solid #eeeeee;
						}
					}
				}
			}
		}

		.invoice {
			color: $theme-color;
			font-size: 28rpx;
			margin-bottom: 30rpx;
			position: absolute;
			left: 30%;
		}
	}
</style>